package LeetCode刷题;

/**
 * @program: Java_Study
 * @author: Xiaofan
 * @createTime: 2022-01-01 11:36
 * @description: Functions of this class is
 **/
public class 数组中重复的数字 {
    class Solution {
        public int findRepeatNumber(int[] nums) {
            int len=nums.length;
            for(int i=0;i<len;i++){
                if(i!=nums[i]){
                    if(nums[i]!=nums[nums[i]]){
                        swap(nums,i,nums[i]);
                    }
                    if(nums[nums[i]]==nums[i]){
                        return nums[i];
                    }
                }
            }
            return -1;
        }
        private void swap(int nums[],int i,int j){
            int temp=nums[i];
            nums[i]=nums[j];
            nums[j]=temp;
        }
    }
}